﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Util;
using Util.Domains.Trees;

namespace IterationLife.System.Models {
    /// <summary>
    /// 行政区域
    /// </summary>
    [Description( "行政区域" )]
    public partial class District : TreeEntityBase<District> {
        /// <summary>
        /// 初始化行政区域
        /// </summary>
        public District()
            : this( Guid.Empty, "", 0 ) {
        }

        /// <summary>
        /// 初始化行政区域
        /// </summary>
        /// <param name="id">行政区域标识</param>
        /// <param name="path">路径</param>
        /// <param name="level">级数</param>
        public District( Guid id, string path, int level )
            : base( id, path, level ) {
        }

        /// <summary>
        /// 编码
        /// </summary>
        [Required(ErrorMessage = "编码不能为空")]
        [StringLength( 10, ErrorMessage = "编码输入过长，不能超过10位" )]
        public string Code { get; set; }
        /// <summary>
        /// 父编码
        /// </summary>
        [StringLength( 10, ErrorMessage = "父编码输入过长，不能超过10位" )]
        public string ParentCode { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        [Required(ErrorMessage = "名称不能为空")]
        [StringLength( 200, ErrorMessage = "名称输入过长，不能超过200位" )]
        public string Name { get; set; }
        /// <summary>
        /// 合并名称
        /// </summary>
        [Required(ErrorMessage = "合并名称不能为空")]
        [StringLength( 500, ErrorMessage = "合并名称输入过长，不能超过500位" )]
        public string MergerName { get; set; }
        /// <summary>
        /// 短名称
        /// </summary>
        [Required(ErrorMessage = "短名称不能为空")]
        [StringLength( 500, ErrorMessage = "短名称输入过长，不能超过500位" )]
        public string ShortName { get; set; }
        /// <summary>
        /// 合并短名称
        /// </summary>
        [Required(ErrorMessage = "合并短名称不能为空")]
        [StringLength( 500, ErrorMessage = "合并短名称输入过长，不能超过500位" )]
        public string MergerShortName { get; set; }
        /// <summary>
        /// 区号
        /// </summary>
        [StringLength( 4, ErrorMessage = "区号输入过长，不能超过4位" )]
        public string TelCode { get; set; }
        /// <summary>
        /// 邮编
        /// </summary>
        [StringLength( 6, ErrorMessage = "邮编输入过长，不能超过6位" )]
        public string ZipCode { get; set; }
        /// <summary>
        /// 拼音简码
        /// </summary>
        [Required(ErrorMessage = "拼音简码不能为空")]
        [StringLength( 200, ErrorMessage = "拼音简码输入过长，不能超过200位" )]
        public string PinYin { get; set; }
        /// <summary>
        /// 全拼
        /// </summary>
        [Required(ErrorMessage = "全拼不能为空")]
        [StringLength( 500, ErrorMessage = "全拼输入过长，不能超过500位" )]
        public string FullPinYin { get; set; }
        /// <summary>
        /// 英文
        /// </summary>
        [Required(ErrorMessage = "英文不能为空")]
        [StringLength( 200, ErrorMessage = "英文输入过长，不能超过200位" )]
        public string English { get; set; }
        /// <summary>
        /// 经度
        /// </summary>
        [Required(ErrorMessage = "经度不能为空")]
        public decimal Longitude { get; set; }
        /// <summary>
        /// 纬度
        /// </summary>
        [Required(ErrorMessage = "纬度不能为空")]
        public decimal Latitude { get; set; }
        /// <summary>
        /// 编码路径
        /// </summary>
        [Required(ErrorMessage = "编码路径不能为空")]
        [StringLength( 800, ErrorMessage = "编码路径输入过长，不能超过800位" )]
        public string CodePath { get; set; }
        
        /// <summary>
        /// 添加描述
        /// </summary>
        protected override void AddDescriptions() {
            AddDescription( "行政区域编号", Id );
            AddDescription( "父编号", ParentId );
            AddDescription( "编码", Code );
            AddDescription( "父编码", ParentCode );
            AddDescription( "名称", Name );
            AddDescription( "合并名称", MergerName );
            AddDescription( "短名称", ShortName );
            AddDescription( "合并短名称", MergerShortName );
            AddDescription( "级数", Level );
            AddDescription( "区号", TelCode );
            AddDescription( "邮编", ZipCode );
            AddDescription( "拼音简码", PinYin );
            AddDescription( "全拼", FullPinYin );
            AddDescription( "英文", English );
            AddDescription( "经度", Longitude );
            AddDescription( "纬度", Latitude );
            AddDescription( "路径", Path );
            AddDescription( "编码路径", CodePath );
            AddDescription( "启用", Enabled.Description() );
            AddDescription( "排序号", SortId );
        }
        
        /// <summary>
        /// 添加变更列表
        /// </summary>
        protected override void AddChanges( District newEntity ) {
            AddChange( "Id", "行政区域编号", Id, newEntity.Id );            
            AddChange( "ParentId", "父编号", ParentId, newEntity.ParentId );
            AddChange( "Code", "编码", Code, newEntity.Code );
            AddChange( "ParentCode", "父编码", ParentCode, newEntity.ParentCode );
            AddChange( "Name", "名称", Name, newEntity.Name );
            AddChange( "MergerName", "合并名称", MergerName, newEntity.MergerName );
            AddChange( "ShortName", "短名称", ShortName, newEntity.ShortName );
            AddChange( "MergerShortName", "合并短名称", MergerShortName, newEntity.MergerShortName );
            AddChange( "Level", "级数", Level, newEntity.Level );
            AddChange( "TelCode", "区号", TelCode, newEntity.TelCode );
            AddChange( "ZipCode", "邮编", ZipCode, newEntity.ZipCode );
            AddChange( "PinYin", "拼音简码", PinYin, newEntity.PinYin );
            AddChange( "FullPinYin", "全拼", FullPinYin, newEntity.FullPinYin );
            AddChange( "English", "英文", English, newEntity.English );
            AddChange( "Longitude", "经度", Longitude, newEntity.Longitude );
            AddChange( "Latitude", "纬度", Latitude, newEntity.Latitude );
            AddChange( "Path", "路径", Path, newEntity.Path );
            AddChange( "CodePath", "编码路径", CodePath, newEntity.CodePath );
            AddChange( "Enabled", "启用", Enabled, newEntity.Enabled );
            AddChange( "SortId", "排序号", SortId, newEntity.SortId );
        }
    }
}